#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minZeroArray(vector<int>& nums, vector<vector<int>>& queries) {
        int ret = 0;
        for (int i = 0; i < nums.size(); i++) {
            if (nums[i] == 0) continue;
            vector<bool> f(nums[i] + 1, false);
            f[0] = true;
            for (int k = 0; k < queries.size(); k++) {
                auto& q = queries[k];
                if (i < q[0] || i > q[1]) continue;
                for (int j = f.size() - 1; j >= q[2]; j--) f[j] = f[j] || f[j - q[2]];
                if (f[nums[i]]) {
                    ret = max(ret, k + 1);
                    break;
                }
            }
            if (!f[nums[i]]) return -1;
        }
        return ret;
    }
};